package ro.bluecube.admlocal.gui.commons;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import javax.swing.JOptionPane;
import javax.swing.JPanel;


public abstract class AbstractForm extends JPanel{
	
	Collection listeners;
	
	public void showForm(){
		initComponents();
		revalidate();
		repaint();
		this.setVisible(true);
	}
	public void hideForm(){
		this.setVisible(false);
	}
	public abstract void initComponents();
	
	public abstract void populate();
	
	public void showMessage(String message){
		JOptionPane.showMessageDialog(this,message);
	}
	
	public void addFormListener(FormListener listener){
		listeners.add(listener);
	}
	public AbstractForm() {
		super();
		listeners = new ArrayList();
	}
	public void handleEvent(FormEvent event){
		for (Iterator iter = listeners.iterator(); iter.hasNext();) {
			FormListener element = (FormListener) iter.next();
			element.performFormEvent((FormEvent) event);
		}
	}
	
	public JPanel getToolBar(){
		return new JPanel();
	}
}
